class AIHealer extends AI{
			
	private var _closestAllyDistance;
	private var _closestAlly:EnemyCharacter;
	private var _closestAllyInDanger:EnemyCharacter;
	private var _lowestHealth:int;
	private var _isInHealRange:boolean;	
	
	public function AIHealer(selectedEnemy:EnemyCharacter, playerList:Array, enemyList:Array){
		super(selectedEnemy, playerList);
		
		checkDistanceRange();
		
		_closestAllyDistance = _lowestHealth = 9999999;
		_closestAlly = _closestAllyInDanger = null;
		_isInHealRange = false;
		
		// Initialise state at the beginning
		if(_selectedEnemy.getTurnsLeft() == 2){
			_selectedEnemy.setDecisionState(EnemyCharacter.DecisionState.ATTACK);
		}
		
		checkAllyHealth(enemyList);			
	}
	
	//Getters
	public function getClosestAllyInDanger():EnemyCharacter { return _closestAllyInDanger; }
	public function getClosestAlly():EnemyCharacter{ return _closestAlly; }
	public function getClosestAllyDistance(){ return _closestAllyDistance; }
	public function getIsInHealRange():boolean{ return _isInHealRange; }
	
	public function getCoverTile(mapReference){
		return getCoverTile(0, mapReference);
	}
	public function getForwardCoverTile(mapReference:Map){
		return getForwardCoverTile(0, mapReference);
	}
	
	// Move to closest Ally instead of enemy
	function setMoveToAlly(){
		_coord = _closestAlly.getCoord();
	}
	
	public function checkAllyHealth(enemyList:Array){
		for (var j = 0; j < enemyList.length; j++)
		{
			var allyCoord :Vector2 = enemyList[j].getCoord();
			var distanceToAlly = Vector2.Distance(_srcCoord, allyCoord);
			var allyHealth:int = enemyList[j].getHealth();
			
			//find ally with lowest hp closest to this enemy
			if(distanceToAlly < _closestAllyDistance && allyHealth < _lowestHealth && !enemyList[j].getIsDead()){					
				_closestAlly = enemyList[j];
				_lowestHealth = allyHealth;				
				_closestAllyDistance = distanceToAlly;
			}
			
			// Can fuzzy health here
			if(enemyList[j].getHealthPercent() <= 0.7 && !enemyList[j].getIsDead()){
				_closestAllyDistance = distanceToAlly;
				_closestAllyInDanger = enemyList[j];
				_closestAlly = _closestAllyInDanger;
				
				// Ensure that state changes only at the beginning
				// if healer must heal, change decision state to heal
				if(_selectedEnemy.getTurnsLeft() == 2){
					_selectedEnemy.setDecisionState(EnemyCharacter.DecisionState.HEAL);
				}
				
				break;
			}
		}			
		
		if(_selectedEnemy.getDecisionState() == EnemyCharacter.DecisionState.HEAL)
			setMoveToAlly();
		
		if(_closestAllyDistance <= _selectedEnemy.getSkillRadius()){
			_isInHealRange = true;
		}
	}
}